package com.kye.express.business.found.subfragment;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.kye.express.R;
import com.kye.express.databinding.FoundwelfareHeadBinding;
import com.kye.express.view.imagecycleview.ImageCycleViewWall;
import com.kye.model.bean.FoundWelfareAdsResult;

class FoundWelfareItemHeadViewBinder extends me.drakeet.multitype.ItemViewBinder<FoundWelfareAdsResult, FoundWelfareItemHeadViewBinder.ViewHolder> {

    private Context mContext;
    public FoundWelfareItemHeadViewBinder(Context context){
        mContext = context;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.foundwelfare_head, parent, false);
        return new ViewHolder(view);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull FoundWelfareAdsResult item) {
        holder.bindData(item);
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private FoundWelfareAdsResult data;
        FoundwelfareHeadBinding dataBinding;

        public ViewHolder(View itemView) {
            super(itemView);
            dataBinding = DataBindingUtil.bind(itemView);
        }

        public void bindData(FoundWelfareAdsResult item) {
            data = item;
            dataBinding.welfareHeadView.setImageResources(item.getImageUrls(), new WelfareViewPageListenner());
        }

        /**
         * 轮播图点击监听
         */
        class WelfareViewPageListenner implements ImageCycleViewWall.ImageCycleViewListener {

            @Override
            public void displayImage(String imageURL, ImageView imageView) {
                imageView.setTag(null);
                Glide.with(mContext).load(imageURL).into(imageView);
            }

            @Override
            public void onImageClick(int position, View imageView) {

            }
        }
    }

}
